﻿<?php 
Error_Reporting(E_ALL & ~E_NOTICE);
include_once('./Snoopy.class.php');
echo getPriceFromPage($_POST['shop'],$_POST['region'],$_POST['model']);

function getPriceFromPage ($shop, $region, $SelectedModel){

switch($shop) {
 	case "mvideo": 
		$Device = 		Array ('HL-1110'=> 'lazernyy-printer-brother-hl-1110r.html','DCP-1510'=> 'lazernoe-mfu-brother-dcp-1510r.html','DCP-7055WR'=> 'lazernoe-mfu-brother-dcp-7055wr.html','DCP-7055R'=> 'lazernoe-mfu-brother-dcp-7055r.html');
		$model = 		$Device[$SelectedModel];
		$pageUrl= 		"http://".$region.".mvideo.ru/products/".$model;
		$PriceParsing = '~productPriceLocal[\s\S]+?:[\s\S]+?(?:"([\s\S]+?)"|null)~';
		break;
		
 	case "eldo": 
		$Device = 		Array ('HL-1110'=> '71088656','DCP-1510'=> '71088868','DCP-7055R'=> '71076362');
		$model = 		$Device[$SelectedModel];
		$pageUrl = 		"http://eldorado.ru/cat/detail/".$model."/&action=changeSubRegion&regsectid=".$region."&backurl=http://www.eldorado.ru/cat/detail/".$model."/";;
		$PriceParsing = "~ecomm_totalvalue: '(\d+?)',~";
		break;
		
 	case "mms": 
		$Device = 		Array ('HL-1110'=> '1211538','DCP-1510'=> '1217979','DCP-7055WR'=> '1167367','DCP-7055R'=> '1137598');
		$model = 		$Device[$SelectedModel];
		$pageUrl = 		"http://m.mediamarkt.ru/item/".$model."?set_mobile_channel=mobile&location=shop_".$region;
		$PriceParsing = "~(\d+?).png|Нет в наличии~";
		break;
 }
		
	$html = new Snoopy;	// установка URL и других необходимых параметров
	$html->fetch($pageUrl);
			if($result = $html->results) { 				
				preg_match($PriceParsing,$result,$matches);
				if (count($matches[0])!= 0){
					return $matches [1];					
				}
				else {
					return ("<a href='".$pageUrl.'>none</a>');
				}
			}
			else {
				return ("err");	
			}
			
}
		
?>